/**
 * Created by oiuyt on 2018/7/18.
 */
import React, { Component } from 'react'
import PropTypes from 'prop-types'
import { connect } from 'react-redux'


class Counter extends Component {
    constructor(props) {
        super(props);
        console.log("dd")
        console.log(props)
        console.log("组件初始化8")
    }
    render() {
        const { value,onDescClick, onIncreaseClick } = this.props
        return (
            <div>
                {JSON.stringify(this.props.value)}
                <button onClick={onDescClick}>Increase</button>
                <span>{value.count}</span>

                <button onClick={onIncreaseClick}>Increase</button>
            </div>
        )
    }
}


Counter.propTypes = {
    value: PropTypes.object.isRequired,
    onDescClick: PropTypes.func.isRequired,
    onIncreaseClick: PropTypes.func.isRequired
}

// Action
const increaseAction = { type: 'increase' }
const descAction = { type: 'desc' }



// Map Redux state to component props
function mapStateToProps(state) {
    return {
        value: state
    }
}


const mapDispatchToProps = (dispatch) => ({
    onIncreaseClick: () => dispatch(increaseAction),
    onDescClick: () => dispatch(descAction)
})

// Connected Component
const Test8 = connect(
    mapStateToProps,
    mapDispatchToProps
)(Counter)


export default Test8
